<template>
  <div>
    <div id="user"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { econe } from "@/api/echarsapi/scone";
export default {
  data() {
    return {
      day: [],
      users: [],
    };
  },
  created() {
    this.getdata();
  },
  mounted() {
    this.echart();
  },
  methods: {
    getdata() {
      econe().then((res) => {
        // console.log(res.data.rows);
        this.day = res.data.rows.map((item) => item.day);
        this.users = res.data.rows.map((item) => item.users);
        // console.log(this.day, this.users);
        this.echart();
      });
    },
    echart() {
      var myChart = echarts.init(document.getElementById("user"));
      let option = {
        backgroundColor: "#f5f9ff",
        // color: ["#78aaf2", "#aed1f7", "#c3dcf8", "#e4f1fc", "#b4c9ef"],
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        label: {
          show: true,
          position: "top",
          color:'#4ED3AD'
        },
        legend: {
          data: ["用户增长数"],
        },
        grid: {
          left: "5%",
          right: "5%",
          bottom: "10%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          data: this.day,
          axisLine: {
            lineStyle: {
              color: "#000",
            },
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            color: "#7a869a",
          },
        },
        yAxis: {
          type: "value",
          splitLine: {
            lineStyle: {
              color: "#e6effc",
            },
          },
          axisLine: {
            show: false,
          },
          axisLabel: {
            color: "#000",
          },
        },
        series: [
          {
            name: "用户增长数",
            data: this.users,
            type: "bar",
            itemStyle: {
                borderRadius: [4, 4, 0, 0],
                color: "#4ED3AD", // 设置柱体颜色
            },
          },
        ],
      };
      myChart.setOption(option);
    },
  },
};
</script>

<style lang="scss" scoped>
#user {
  width: 100%;
  height: 500px;
}
</style>